<template>
	<div>
		<div flex>
		</div>
		<base-table ref="customtable" :border="true" :showIndex="true" :tabLoading.sync="tabLoading" :tableData="tableData"
			:tableColumn="tableColumn" :funData="[]" :indexOperate="true" @newRow="add">
			<template v-slot:operate="{ row }">
        		<el-tooltip class="item" effect="dark" content="删除当前行" placement="top">
        		  <i class="el-icon-delete" style="color: red; font-size: 16px; margin-right: 10px" @click="del(row)"></i>  
        		</el-tooltip>
			</template>
      		<template v-slot:personName="{ row }">
      		  <el-input v-model="row.personName" clearable type="text"></el-input>
      		</template>
			<template v-slot:position="{ row }">
      		  <el-input v-model="row.position" clearable type="text"></el-input>
      		</template>
      		<template v-slot:phone="{ row }">
      		  <el-input
      		    v-model="row.phone"
      		    @input="(v) => (row.phone = v.replace(/[^\d]/g, ''))"
      		  >
      		  </el-input>
      		</template>
			<!-- <template v-slot:phone="{ row }">
      		  <el-input v-model="row.phone" clearable type="text"></el-input>
      		</template> -->
			<template v-slot:remark="{ row }">
      		  <el-input v-model="row.remark" clearable type="text"></el-input>
      		</template>
      		<template v-slot:department="{ row }">
      		  <div flex @click="elDialogClick(row.index)">
      		    <p
      		      class="single"
      		      :style="{ color: row.department ? '#000' : '#c0c4cc' }"
      		      style="width: 100%"
      		    >
      		      {{ row.department ? row.department : "请点击选择" }}
      		    </p>
      		    <i class="el-icon-more" style="margin-top: 6px;color: #c0c4cc"></i>
      		  </div>
      </template>
		</base-table>
		<base-organization ref="baseOrganization" :menuData="organMenuData" @handleConfirmClick="organizationHandleConfirm"></base-organization>
	</div>
</template>

<script>
import baseTable from "@/components/base/baseTable";
import basePage from '@/components/base/basePage'
import baseChoice from "@/components/base/baseChoice/index.vue";
import baseDialog from "@/components/base/BaseNewDialog/index.vue";
import baseOrganization from "@/components/base/baseOrganization/index.vue";
import { DelBusiness } from '@/api/apis/leadManagement'
import { GetOrganTree} from "@/api/apis/organization";

import { getCompanyId } from "@/utils/auth";
export default {
	name: "equipmentDetails",
	components: {
		baseTable,
		basePage,
		baseDialog,
		baseChoice,
		baseOrganization
	},
	data() {
		return {
			organMenuData: [],
			loading: false,
			tableHeight: '65vh',
			optionIndex: '',
			tabLoading: false,
			tableData: [],
			tableColumn: [
				{
					label: '姓名',
					prop: 'personName',
					tooltip: true,
				},
				{
					label: '部门',
					prop: 'department',
					tooltip: true,
				},
				{
					label: '职位',
					prop: 'position',
					tooltip: true,
				},
				{
					label: '联系方式',
					prop: 'phone',
					tooltip: true,
				},
				{
					label: '备注',
					prop: 'remark',
					tooltip: true,
					width: '600'
				},
				{
					label: "操作",
					prop: "operate",
					width: "70",
				},
			],
			pageModel: {
				page: 1, //当前页码
				limit: 10, //每页显示多少
				cusClassify: "", //树形分类id
				sequence: "", //排列方式
				sequenceName: "", //需要排列的字段名
			},
		}
	},
	computed: {},
	created() {
		this.init()
	},
	methods: {
		init() {
			this.getMenuData()
		},
		// 组织机构
    	async getMenuData() {
    	  let params = {
    	    // CompanyID: 1
    	    companyID: this.$store.state.user.companyID
    	      ? this.$store.state.user.companyID
    	      : getCompanyId(),
    	  };
    	  let res = await GetOrganTree(params);
    	  this.organMenuData = JSON.parse(res.data[0]);
    	},
		// 打开组织机构
		elDialogClick(index) {
        	this.$refs.baseOrganization.dialogVisible = true;
			this.optionIndex = index;
		},
		// 组织机构确认
		organizationHandleConfirm(item) {
			this.$set(this.tableData[this.optionIndex], 'department', item.label)
			this.$refs.baseOrganization.qingkong();
      		this.$refs.baseOrganization.dialogVisible = false;
		},
		//添加
		add() {
			let arr = {}
			this.tableData.push(arr)
		},
		async del(row) {
			this.$confirm('确认删除该明细吗?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				if (row.mainID && this.$route.query.name == '编辑线索') {
					DelBusiness({ id: row.detail_ID}).then ( res => {
						if (res.success == "true") {
							this.$emit("renovate");
							this.$message({
								message: "删除成功",
								type: "success",
							});
							this.tableData.splice(row.index, 1);
							this.$emit('renew')
						}
					})
				} else {
					this.tableData.splice(row.index, 1);
				}
			}).catch(() => {
				this.$message({
					type: 'info',
					message: '已取消删除'
				});
			});
		},
	}
}
</script>

<style>
.el-table th>.cell {
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;

}
</style>
<style scoped lang="scss">
>>>.el-radio__label {
	// display: none;
}

.iconButton {
	padding: 10px 12px;
	color: white;
	margin: 5px;
}

.iconButton.add {
	background-color: #409eff !important;
}

.iconButton.del {
	background-color: #f56c6c !important;
}
</style>
